<?php

/** 
 * @todo 分页类
 * @author Star.li
 * @copyright FZD
 * @update 2011-12-10
 * 
 */
class page {
	//TODO - Insert your code here
	private $url   = "";
	//总记录	
	private $total = 0;
	//当前页
	private $page  = 0;
	//总页数
	private $pageCount = 0;
	//参数
	private $params = array();
	function __construct($url,$pageCount,$total,$page,$params='') {
	
		//TODO - Insert your code here
		$this->url = $url."?";
		$this->total = $total;
		$this->pageCount = $pageCount;
		$this->page  = $page;
		$this->params = $params;
	}
	
	function assign(){
		
		$pre = ($this->page-1)<1?1:($this->page-1);
		$next = ($this->page+1)>$this->pageCount?$this->pageCount:($this->page+1);
		
		if(!empty($this->params)){
			foreach($this->params as $k=>$v){
				$this->url .= "&".$k."=".$v;
			}
		}
		$html  = '<p style="text-align:left; font-size:14px;">';
		$html .= '共有记录<span style="color:#33acb4">'.$this->total.'</span>条，';
		$html .= '共<span style="color:#33acb4">'.$this->pageCount.'</span>页，';
		$html .= '当前第<span style="color:#33acb4">'.$this->page.'</span>页&nbsp;&nbsp;&nbsp;';
		
		if($this->pageCount < 5){
			for($i = 1;$i<=$this->pageCount;$i++){
				$html .= '<a href="'.$this->url."&page=".$i.'">'.$i.'</a>&nbsp;&nbsp;&nbsp;';
			}
		}else{
			$html .= '<a href="'.$this->url."&page=1".'">1</a>&nbsp;&nbsp;&nbsp;';
			$s = ($this->page - 2)>2?($this->page - 2):2;
			$e = ($this->page + 2)>($this->pageCount-1)?($this->pageCount-1):($this->page + 2);
			if($s > 2){
				$html .= '...&nbsp;';
			}
			for($i = $s;$i<=$e;$i++){
				$html .= '<a href="'.$this->url."&page=".$i.'">'.$i.'</a>&nbsp;&nbsp;&nbsp;';
			}
			if($e < ($this->pageCount-1)){
				$html .= '...&nbsp;';
			}
			//for($i = )
			$html .= '<a href="'.$this->url."&page=".$this->pageCount.'">'.$this->pageCount.'</a>&nbsp;&nbsp;&nbsp;';
		}
		return $html;
	}
	/**
	 * 
	 */
	function __destruct() {
	
		//TODO - Insert your code here
	}
}

?>